package web.suzy.oj.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import web.suzy.oj.pojo.vo.ConfigVO;

/**
 * YangSuzy 软件工作室
 * 类名: ConfigUtils
 * 描述: 配置工具类
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/17 18:20
 */
@Component
@Slf4j(topic = "suzyoj")
public class ConfigUtils {
    @Autowired
    private ConfigVO configVo;

    /**
     * 方法名: getConfigContent
     * 描述: 获取配置 yml文本
     *
     * @return java.lang.String
     * @date 2022/11/17 18:20
     * @auther YangSuzy
     **/
    public String getConfigContent() {
        return buildYamlStr(configVo);
    }

    /**
     * 方法名: buildYamlStr
     * 描述: 构建 yml文件内容
     *
     * @param configVo
     * @return java.lang.String
     * @date 2022/11/17 18:22
     * @auther YangSuzy
     **/
    public String buildYamlStr(ConfigVO configVo) {
        return "suzyoj:\n" +
                "  jwt:\n" +
                "    # 加密秘钥\n" +
                "    secret: " + configVo.getTokenSecret() + "\n" +
                "    # token有效时长，1天，单位秒\n" +
                "    expire: " + configVo.getTokenExpire() + "\n" +
                "    checkRefreshExpire: " + configVo.getCheckRefreshExpire() + "\n" +
                "    header: token\n" +
                "  judge:\n" +
                "    # 调用判题服务器的token\n" +
                "    token: " + configVo.getJudgeToken() + "\n" +
                "  db:\n" +
                "    host: " + configVo.getMysqlHost() + "\n" +
                "    port: " + configVo.getMysqlPort() + "\n" +
                "    public-host: " + configVo.getMysqlPublicHost() + "\n" +
                "    public-port: " + configVo.getMysqlPublicPort() + "\n" +
                "    name: " + configVo.getMysqlDBName() + "\n" +
                "    username: " + configVo.getMysqlUsername() + "\n" +
                "    password: " + configVo.getMysqlPassword() + "\n" +
                "  redis:\n" +
                "    host: " + configVo.getRedisHost() + "\n" +
                "    port: " + configVo.getRedisPort() + "\n" +
                "    password: " + configVo.getRedisPassword();
    }


}
